package com.gexiaobao.pigeon.ui.adapter

import android.annotation.SuppressLint
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.Auction
import com.gexiaobao.pigeon.databinding.ItemLayoutAuctionTodayBinding

/**
 * @Author      : hxw
 * @Date        : 2024/11/12 11:40
 * @Describe    : 专题列表
 */
class AdapterSpecialAuction(data: ArrayList<Auction>) :
    BaseQuickAdapter<Auction, DataBindBaseViewHolder>(R.layout.item_layout_auction_today, data) {

    private var mOnItemClickListener: OnAuctionPigeonClickListener? = null

    @SuppressLint("NotifyDataSetChanged")
    override fun convert(holder: DataBindBaseViewHolder, item: Auction) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemLayoutAuctionTodayBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        holder.setGone(R.id.llProxyBidding,true)
        val orgType = when (item.orgType) {
            2 -> "协会"
            1 -> "俱乐部"
            else -> "公棚"
        }
        holder.setText(R.id.tvItemOrgType, orgType)
        holder.setText(R.id.tvItemSpecialOrgNameCount, item.orgName + "   " + item.cnt + "羽")

        holder.itemView.apply {
            binding.recyclerView.adapter = null
            if (item.items.isEmpty()) {
                holder.setGone(R.id.recyclerView, true)
                return
            }
            holder.setGone(R.id.recyclerView, false)
            val mAdapter = AdapterAuctionPigeon(arrayListOf())
            binding.recyclerView.apply {
                layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
                adapter = mAdapter
                mAdapter.setList(item.items)
                mAdapter.notifyDataSetChanged()
            }

            mAdapter.setOnItemClickListener { _, _, position ->
                mOnItemClickListener?.onItemClick(holder.layoutPosition)
            }
        }
    }

    fun setOnAuctionPigeonClickListener(listener: OnAuctionPigeonClickListener?) {
        mOnItemClickListener = listener
    }

    interface OnAuctionPigeonClickListener {
        fun onItemClick(position: Int)
    }
}